package proxy.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 代理增强类
 * @author wangxun
 * @version 1.0
 * @description: TODO
 * @date 2020/11/13 9:46 上午
 */
public class StarInvocationHandler implements InvocationHandler {
    /**
     * 目标对象
     */
    private Object target;

    public StarInvocationHandler(Object target) {
        this.target = target;
    }

    public static final String SIGN  = "sign";
    public static final String SING  = "sing";
    public static final String COLLECT  = "collect";

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        String name = method.getName();
        if(SIGN.equals(name)){
            System.out.println("接待");
            System.out.println("谈合同");
            // 执行方法
            method.invoke(target,args);
            System.out.println("跟踪");
        }else if(SING.equals(name)){
            method.invoke(target,args);
        }else if(COLLECT.equals(name)){
            System.out.println("催促");
            // 执行方法
            method.invoke(target,args);
            System.out.println("告知对方");
        }

        return null;
    }
}
